#!/bin/bash

dt=`date -d '1 days ago' '+%Y-%m-%d'` # 获取昨日时间

# 日志文件定义
FULL_ADD_LOG="/root/aaa/program_2_hivesql/full_add.log"
INC_ADD_LOG="/root/aaa/program_2_hivesql/inc_add.log"

echo "======= 开始ETL处理，处理日期: $dt ======="

# ods -> dwd 全量
echo "$(date '+%Y-%m-%d %H:%M:%S') - 开始ODS->DWD全量处理" >> $FULL_ADD_LOG
nohup hive -hivevar etl_dt="$dt" -f /root/aaa/program_2_hivesql/ods_to_dwd_full_add.txt >> $FULL_ADD_LOG 2>&1
test1=$?

# ods -> dwd 增量
echo "$(date '+%Y-%m-%d %H:%M:%S') - 开始ODS->DWD增量处理" >> $FULL_ADD_LOG
nohup hive -hivevar etl_dt="$dt" -f /root/aaa/program_2_hivesql/ods_to_dwd_inc_add.txt >> $FULL_ADD_LOG 2>&1
test2=$?

# 数据传输检验
if [ "$test1" -ne 0 ] || [ "$test2" -ne 0 ]; then
    echo " ODS -> DWD 数据增量出现错误，请前往查看日志排查错误"
    exit
fi
echo " ODS -> DWD 数据传输完成"

# dwd -> dws
echo "$(date '+%Y-%m-%d %H:%M:%S') - 开始DWD->DWS处理" >> $INC_ADD_LOG
nohup hive -hivevar etl_dt="$dt" -f /root/aaa/program_2_hivesql/dwd_to_dws_full_add.txt >> $INC_ADD_LOG 2>&1

# 验证数据传输成功与否
if [ $? -ne 0 ]; then
    echo " DWD -> DWS 数据增量出现错误，请前往查看日志排查错误"
    exit
fi
echo " DWD -> DWS 数据传输完成"

# dws -> ads
echo "$(date '+%Y-%m-%d %H:%M:%S') - 开始DWS->ADS处理" >> $INC_ADD_LOG
nohup hive -hivevar etl_dt="$dt" -f /root/aaa/program_2_hivesql/dws_to_ads_full_add.txt >> $INC_ADD_LOG 2>&1

# 验证数据传输成功与否
if [ $? -ne 0 ]; then
    echo " DWS -> ADS 数据增量出现错误，请前往查看日志排查错误"
    exit
fi
echo " DWS -> ADS 数据传输完成"

echo " 全部数据传输完成！！ "